package sk.stancel.peter.sudoku;

import java.util.List;

import sk.stancel.peter.sudoku.R;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.RelativeLayout;
import android.widget.TextView;

/**
 * 
 * @author Peter Stancel
 */
public class SavedSudokuAdapter extends ArrayAdapter<String>{

	private List<String> list;
	private Context context;
	
	public SavedSudokuAdapter(Context context, List<String> list) {
		super(context, 0, list);
		this.list = list;
		this.context = context;
	}
	
	@Override
	public int getCount() {
		return list.size();
	}

	@Override
	public String getItem(int position) {
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		String path = list.get(position);
		View customView = LayoutInflater.from(context).inflate(R.layout.item_saved_sudoku, null);
		
		TextView tv = (TextView) customView.findViewById(R.id.text_saved_sudoku);
		int i = path.lastIndexOf("/");
		if(i != -1){
			path = path.substring(i + 1).replace(".sud", "");
		}
		tv.setText(path);
		tv.setTypeface(Sudoku.getFont());
		
		RelativeLayout ll = (RelativeLayout) customView.findViewById(R.id.layuout_saved_sudoku);
		if((position % 2) != 0){
			ll.setBackgroundResource(R.drawable.button);
		}else ll.setBackgroundResource(R.drawable.button_back);
		
		return customView;
	}
}
